#pragma once

namespace raycast {
	static const char *_vertexcode = 
	"#version 330 core \n"
	"layout(location = 0) in vec3 position; \n"
	"uniform mat4 mvp; \n"
	"void main() \n"
	"{ \n"
	"	gl_Position = mvp * vec4(position, 1.0); \n"
	"} \n";

	static const char *_fragmentcode =
	"#version 330 core \n"
	"uniform vec3 inputcolor; \n"
	"out vec4 color; \n"
	"void main() \n"
	"{ \n"
	"	color = vec4(inputcolor, 1.0); \n"
	"} \n";

	class color_shader {
	private:
		GLuint _program;
		GLuint _mvp_loc;
		GLuint _inputcolor_loc;
		
	public:
		~color_shader() {
			if (_program != 0)	
				glDeleteProgram(_program);
		}

		bool
		init() {
			_program = shader_linkprogram_str(_vertexcode, _fragmentcode);
			if (_program == 0)
				return false;
			_mvp_loc = glGetUniformLocation(_program, "mvp");
			_inputcolor_loc = glGetUniformLocation(_program, "inputcolor");
			return true;
		}

		void
		setuniform(const glm::mat4 &matrix, GLfloat r, GLfloat g, GLfloat b) {
			glUniformMatrix4fv(_mvp_loc, 1, GL_FALSE, glm::value_ptr(matrix));
			glUniform3f(_inputcolor_loc, r, g, b);
		}

		void
		useprogram() {
			glUseProgram(_program);
		}
	};
}
